#ifndef MESSAGE_H
#define MESSAGE_H
#include <iostream>
#include <map>

#include <stdio.h>
#include <string.h>


// types of messages:
// these numbers are needed by the message receiver to identify the message purely by it's byte data
enum  MessageType
{
// TODO: More message types
	//OBJECT,
	//MOUSE,
	//MOVE
	CONTROL,
	PLAYER,
	ITEM
};

// the header information is needed by the message receiver to identify type and length of each message

class ID {
public:
	ID(unsigned int objectID) {
		_object = objectID;
		_machine = ID::machineID;
	}
	~ID() {}

	unsigned long _object;
	unsigned long _machine;

	friend bool operator < (const ID& id1, const ID& id2)
	{
		if (id1._machine < id2._machine) return true;
		if (id1._machine != id2._machine) return false;
		return id1._object < id2._object;
	}


	static unsigned long machineID;
};

class MessageHeader
{
	protected:
		MessageHeader(int type, int length, ID id);
		~MessageHeader();

	public:
		unsigned int _type;
		unsigned int _length;
		ID _id;
};


class ObjectMessage: public MessageHeader
{
	protected:
		ObjectMessage(int type, int length, ID id);
		~ObjectMessage();

	public:

		//Quaternion
		float attitude;	
		float fX;		
		float fY;		
		float fZ;		

		//World Position
		float positionX;	
		float positionY;
		float positionZ;
};

class ControlMessage: public MessageHeader
{
	public:
		ControlMessage(ID id);
		~ControlMessage();

		signed long mouseX;
		signed long mouseY;

		signed char moveX;
		signed char moveY;
		signed char moveZ;

		unsigned char fire;
};


class PlayerMessage: public ObjectMessage
{
	public:
		PlayerMessage(ID id);
		~PlayerMessage();

		unsigned long machineID;
};

class ItemMessage: public ObjectMessage
{
	public:
		ItemMessage(ID id);
		~ItemMessage();

		unsigned long itemType;
};

#endif
